<?php

namespace App\Repositories\Impl;

use App\Models\Branch;
use App\Repositories\Contracts\BranchRepository;
use App\Repositories\Transformers\BranchTransformer;
use App\Repositories\Transformers\BranchListTransformer;

class BranchRepositoryImpl implements BranchRepository
{
    public function paginate($perPage, $filter)
    {
        $result = Branch::paginate($perPage);
        return $result;
    }

    public function find($id, $columns = ['*'])
    {
        $branch = Branch::find($id, $columns);
        $result = fractal($branch, new BranchTransformer());
        return $result->toArray();

    }

    public function findByFilter($filter, $columns = ['*'])
    {
        return Branch::where($filter)->first($columns);
    }

    public function getAll($param)
    {
        $branch = Branch::where($param)->get();
        $result = fractal($branch, new BranchListTransformer());
        return $result->toArray();
    }

    public function store($data)
    {
        return Branch::create($data);
    }

    public function update($data, $id)
    {
        return Branch::whereId($id)->update($data);
    }

    public function updateByFilter($data, $where)
    {
        return Branch::where($where)->update($data);
    }

    public function delete($id)
    {
        return Branch::whereId($id)->delete();
    }
}
